export default {
	data() {
		return {
			curId: 0,
			validate: {}, //验证对象
			id: null, //结题id
      studentCurriculum: {}, //课程信息
			portalConfigList: [], //友情链接信息
			fatherIndex: 0, //一级菜单index
		}
	},
	created() { //调用方法
		//初始化课程
		let that = this;
		//初始化友情连接信息
		that.$post(
				that.urls.getAllPortalConfigList, {
					"type": 1
				}
			)
			.then(function(res) {
				if(res.success) {
					that.portalConfigList = res.data;
				}
			})
	},
	updated:function(){
		if(this.getParamValue("fatherIndex")){
			this.fatherIndex=this.getParamValue("fatherIndex");
		}
		if(this.getParamValue("childIndex")){
			this.childIndex=this.getParamValue("childIndex");
		}
	},
	mounted() {
    let that = this;
	  UE.delEditor('editor');
    var ue = UE.getEditor('editor',{maximumWords: 10000});
    UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl;
    UE.Editor.prototype.getActionUrl = function(action) {
      if (action == 'uploadimage' || action == 'uploadscrawl' || action == 'uploadimage') {
        return that.urls.uploadUediter;
      } else if (action == 'uploadvideo') {//视频
        return that.urls.uploadUediter;
      } else if (action == 'uploadfile') {//附件
        return that.urls.uploadUediter;
      } else {
        return this._bkGetActionUrl.call(this, action);
      }
    };

    //获取课程uuid
    let uuid = that.get("reportWritingUuid");
    that.$post(
      that.urls.getStudentCurriculum, {
        "uuid": uuid
      }
    )
    .then(function(res) {
      if(res.success) {
        that.studentCurriculum = res.data;
        ue.ready(function() {
          ue.setContent(that.studentCurriculum.report);
        });
      }
    })
		//加载表单验证
		this.validate = $("#certificateCompletionForm").validate({
			ignore: [],
			rules: {
				report: { // 结题报告
					required: true/*,
					maxlength: 10000*/
				}
			},
			messages: {
				report: { // 结题报告
					required: "请输入结题报告"/*,
					maxlength: "请输入长度小于10000"*/
				}
			},
			/*errorElement: "em",
			errorPlacement: function(error, element) {
				error.appendTo(element.parents(".error-box").children(".error-msg"));
			}*/
		});
	},
	methods: { //写函数方法
		//用户下拉信息鼠标事件
		showUl: function() {
			$(".wkp-right>div>ul").css("display", "block");
		},
		leaveDiv: function() {
			$(".wkp-right>div>ul").css("display", "none");
		},
		//保存结题报告
		saveReport: function() {
			let that = this;
			let flg = that.validate.form();
			if(flg) {
				let dataObj = that.combinationFormObject(that.validate.currentForm);
				that.$post(
						that.urls.updateStudentCurriculumReport,
						dataObj
					)
					.then(function(res) {
						let msg = "";
						if(res.success) {
							that.id = res.data;
							msg = "保存结题报告成功！";
              that.pressRelease();
						} else {
							msg = "保存结题报告失败！";
						}
						layer.msg(msg, {
							time: 3000, //3s后自动关闭
						});
					})
			}
		},
    //返回结业列表页
    pressRelease: function() {
      var that = this;
      that.$router.push({
        path: "completionReport?fatherIndex="+this.fatherIndex,
      })
    },
	}
}
